#include"head.h"


bool validate_login(int net_fd){

    char user_name[32] = {0};
    char password[32] = {0};

    int user_name_len;//参数个数
    int recv_byte = recv(net_fd, &user_name_len, sizeof(int), 0);
    if(recv_byte == 0){
        return false;
    }

    recv(net_fd, user_name, user_name_len, 0);
    recv(net_fd, password, sizeof(password), 0);
    printf("User name: %s  password: %s\n", user_name, password);


    DIR* pdir = opendir(".");
    long loc = telldir(pdir);
    struct dirent* pdirent ;


    while(1) {
        // 事先记录目录流的位置
        //printf("validate, while\n"); 
        long tmploc = telldir(pdir);
        pdirent = readdir(pdir);
        if(pdirent == NULL) break;

        if (strcmp(pdirent->d_name, user_name) == 0) {
            int login = 1;
            send(net_fd, &login, sizeof(int), MSG_NOSIGNAL);
            return true;
        }

    }

    int stat = 0;
    send(net_fd, &stat, sizeof(int), MSG_NOSIGNAL);

    return false;
}
